﻿
Imports System.IO
Imports std
Imports xmlctrl
Imports webctrl
Imports elpmis

Public MustInherit Class _lpmscontrol
    Inherits xmltext

    Protected MustOverride Function app() As lpmsmonitor
    Private parameters As iParameters = Nothing

    Private Sub _new(ByVal parameters As iParameters)
        Me.parameters = parameters
    End Sub

    Protected Sub New(ByVal buff As Stream, _
                      ByVal parameters As iParameters)
        MyBase.New(textEncodingEnum.none, buff)
        _new(parameters)
    End Sub

    Protected Sub New(ByVal page As xhtmlpage, _
                      ByVal buff As Stream, _
                      ByVal parameters As parameters_t)
        MyBase.New(textEncodingEnum.none, buff)
        If parameters Is Nothing Then
            parameters = New parameters_t()
        End If
        parameters.push_back(make_pair("page", httpFunctions.xhtmlpagecreator.create_bare_variable(page)))
        _new(parameters)
    End Sub

    Protected Shadows Sub render(ByVal script As String)
        lpmsmonitor.invokerender(app(), text(), parameters)
    End Sub
End Class

Public Class nameLpmsControl
    Inherits _lpmscontrol

    Private name As String = Nothing
    Private _app As lpmsmonitor = Nothing
    Private script As String = Nothing

    Private Sub _new(ByVal name As String)
        copy(Me.name, name)
        _app = findlpmsengine(name, script)
        render(script)
    End Sub

    Public Sub New(ByVal name As String, Optional ByVal buff As Stream = Nothing, _
                   Optional ByVal parameters As iParameters = Nothing)
        MyBase.New(buff, parameters)
        _new(name)
    End Sub

    Public Sub New(ByVal page As xhtmlpage, ByVal name As String, _
                   Optional ByVal buff As Stream = Nothing, _
                   Optional ByVal parameters As parameters_t = Nothing)
        MyBase.New(page, buff, parameters)
        _new(name)
    End Sub

    Protected Overrides Function app() As lpmsmonitor
        Return _app
    End Function
End Class

Public Class scriptLpmsControl
    Inherits _lpmscontrol

    Private script As String = Nothing
    Private _app As lpmsmonitor = Nothing

    Private Sub _new(ByVal script As String)
        copy(Me.script, script)
        _app = lpmsengine(script)
        render(script)
    End Sub

    Public Sub New(ByVal script As String, Optional ByVal buff As Stream = Nothing, _
                   Optional ByVal parameters As iParameters = Nothing)
        MyBase.New(buff, parameters)
        _new(script)
    End Sub

    Public Sub New(ByVal page As xhtmlpage, ByVal script As String, _
                   Optional ByVal buff As Stream = Nothing, _
                   Optional ByVal parameters As parameters_t = Nothing)
        MyBase.New(page, buff, parameters)
        _new(script)
    End Sub

    Protected Overrides Function app() As lpmsmonitor
        Return _app
    End Function
End Class